package com.share.algorithm.queue;

/**
 * @desc:
 * @author:caifan
 * @date:2020/6/14
 */
public class ArrayQueue {

    private int data[];//数据
    private int head = 0;//头
    private int tail = 0;//尾
    private int n = 0;//数组大小

    public ArrayQueue(int cap) {
        data = new int[cap];
        n = cap;
    }

    /**
     * 入队
     * @param i
     */
    public void push(int i) {
        if (tail == n) {
            return;
        }
        data[tail] = i;
        tail++;
    }

    /**
     * 出队
     */
    public Integer pop() {
        if (isEmpty()) {
            return -1;
        }
        Integer temp = data[head];
        head++;
        return temp;
    }

    public boolean isEmpty() {
        if (head == tail) {
            return true;
        }
        return false;
    }
}
